<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <ul>
        
    </ul>
    
    <script>
        var _ws = new WebSocket("ws://192.168.43.15:8611/ws");
       var _ul = document.querySelector("ul");
       window._write = function(msg) {
          var _li  = document.createElement("li");
          _li.innerHTML=msg;
          _ul.appendChild(_li);
       }
        _ws.onopen = function(){
            window._write("连接服务端...");
            window._write("发送消息：你好服务端...");
            _ws.send(JSON.stringify({ 
						cmd:10, 
						extAttr:{
							userId:"1008612"
						}
				}));

        }
        _ws.onclose = function(){
            window._write("连接关闭...");
        }
        _ws.onmessage=function(eve){
			var obj = JSON.parse(eve.data)
            window._write("收到消息；"+obj.content);

            
        }
        _ws.onerror = function(){
            window._write("出现异常..");
        }

    </script>
</body>
</html>